define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search'],
function($, validate) {
  return {
    
    init: function() {
        this.initPage();
        this.initQuery();
      },
      
      initPage: function(){
          $('.btn-remove').on('click', function(e){
              $('input').val('');
              $('.select2-search-choice').remove();
              $('select[name="companyIds"]').val("请选择").trigger("change");
          });
      },
      
      initQuery: function() {
          
        $(document).find('form').bt_validate();
        $('select[name="companyIds"]').select2({
          theme: "classic",
          placeholder : '请选择',
          minimumResultsForSearch : -1,
          allowClear : true,
        });
        
        var options = {
          time: 1000,
          url: window.__CTX__.root + "/load-places/query",
          queryName: "code",
          value: ["id"],
          display: ["facilityCode", "facilityName"]
        }
        
        $('.fromloadplace-search').koalaSearch(options);
        $('.toloadplace-search').koalaSearch(options);
        
        $(document).on("koala.search.value.changed", ".fromloadplace-search, .toloadplace-search", function(){
          console.log($(this).next().val());
          // TODO 其他查询后的逻辑
        })
      }
    }
  })